package com.blb.eduorderservice.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.blb.common.entity.UserCourseOrder;
import com.blb.eduorderservice.mapper.OrderMapper;
import com.blb.eduorderservice.service.IOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class IOrderServiceImpl extends ServiceImpl<OrderMapper, UserCourseOrder> implements IOrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Override
    public void saveOrder(UserCourseOrder order) {
        orderMapper.insert(order);
    }

    @Override
    public UserCourseOrder changeOrderStatus(String tradeNo, long status) {
        UserCourseOrder order = orderMapper.selectOrderByTradeNo(tradeNo);
        orderMapper.updateOrderStatus(tradeNo, status);
        order.setStatus(status);
        return order;
    }

    @Override
    public List<UserCourseOrder> findUserOrders(long userId) {
        List<UserCourseOrder> orders = orderMapper.selectOrdersByUserId(userId);
        return orders;
    }

    @Override
    public void deleteOrder(long orderId) {
        UserCourseOrder order = orderMapper.selectById(orderId);
        order.setIsDel(1);
        orderMapper.updateById(order);
    }

    @Override
    public UserCourseOrder getOrderByTradeNo(String tradeNo){
        UserCourseOrder order = orderMapper.selectOrderByTradeNo(tradeNo);
        return order;
    }
}
